package com.by.controller.shop;


import com.by.entity.dto.Spu;
import com.by.entity.dto.SpuSearch;
import com.by.service.ProductService;
import com.by.utils.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/api")
public class ProductController {

    @Autowired
    ProductService productService;


//    用来增加商品
    @PutMapping("product/save")
    public AjaxResult saveProduct(@RequestBody Spu spu) {

        AjaxResult ajaxResult1 = productService.saveProduct(spu);


        return ajaxResult1;
    }

//    商家查询商品列表
//     1 通过商品名称，状态，商品分类类型可以进行模糊查询
//     2 将查询结果进行分页显示给前端
    @PostMapping("product/search")
    public AjaxResult searchProduct(@RequestParam(defaultValue = "1")int PageNo,
                                    @RequestParam(defaultValue = "10")int PageSize,
                                    @RequestBody SpuSearch spuSearch) {

        AjaxResult ajaxResult=productService.searchProduct(PageNo,PageSize,spuSearch);

        return ajaxResult;

    }

}
